package com.dyz.leetcode._19_greedy;

import java.util.Arrays;

public class _621_leastInterval {
    public int leastInterval(char[] tasks, int n) {
        int [] record = new int[26];
        for(char c : tasks){
            record[c-'A']++;
        }
        Arrays.sort(record);
        int max = record[25]-1; //需要多少行
        int space = max * n;//行乘以列

        for(int i=24; i>=0; i--){
            space -= Math.min(max, record[i]);
        }

        return space>0? tasks.length+space:tasks.length;
    }
}
